package com.scy.java.io.output;

import java.io.FileWriter;
import java.io.IOException;

//文件输出流写出char[]数据
public class FileWriterWriteChar {
    public static void main(String[] args) {
        FileWriter fileWriter=null;
        try {
            //给定要读取的文件名称
            fileWriter = new FileWriter("fw.txt");
            //字符串转化字符数组
            char[] chars = "java程序员".toCharArray();
//            fileWriter.write(chars);
//            fileWriter.write();
            //写出char[]中的从0位置开始长度为数组长度的char[]容器
            fileWriter.write(chars,0,chars.length);
            System.out.println("写入完毕");
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
                //关闭流
                if (fileWriter != null) {
                    try {
//                        //程序堵塞
//                        Thread.sleep(5000);
                        fileWriter.close();
                        System.out.println("字符输出流已关闭。。。");
                    } catch (IOException e) {
                        throw new RuntimeException(e);
//                    }catch (InterruptedException e) {
//                        throw new RuntimeException(e);
                    }

                }
            }


    }

}
